package com.lc.qianrenshiye.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.conn.MessageListGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/11/24.
 */
public class MessageCenterAdapter extends ArrayAdapter<MessageListGet.MessageEntity>{

    private List<MessageListGet.MessageEntity> lists;
    private Context context;
    private LayoutInflater layoutInflater;

    public MessageCenterAdapter(Context context, List<MessageListGet.MessageEntity> lists) {
        super(context, 0, lists);

        layoutInflater = LayoutInflater.from(context);

        this.context = context;

        this.lists = lists;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MessageListGet.MessageEntity messageEntity = getItem(position);

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_message_center, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        if (TextUtils.isEmpty(messageEntity.time)) {

            viewHolder.item_message_center_time_tv.setVisibility(View.INVISIBLE);

        } else {

            viewHolder.item_message_center_time_tv.setVisibility(View.VISIBLE);
            viewHolder.item_message_center_time_tv.setText(messageEntity.time);

        }

        viewHolder.item_message_center_content_tv.setText(messageEntity.title);

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.item_message_center_time_tv) private TextView item_message_center_time_tv;
        @BoundView(R.id.item_message_center_content_tv) private TextView item_message_center_content_tv;

    }


}
